package com.gpt.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.gpt.article.domain.GptSpiderItem;
import com.gpt.article.service.IGptSpiderItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采集来源Controller
 * 
 * @author zhuzi
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/article/spiderItem")
public class GptSpiderItemController extends BaseController
{
    @Autowired
    private IGptSpiderItemService gptSpiderItemService;

    /**
     * 查询采集来源列表
     */
    @PreAuthorize("@ss.hasPermi('article:spiderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(GptSpiderItem gptSpiderItem)
    {
        startPage();
        List<GptSpiderItem> list = gptSpiderItemService.selectGptSpiderItemList(gptSpiderItem);
        return getDataTable(list);
    }

    /**
     * 导出采集来源列表
     */
    @PreAuthorize("@ss.hasPermi('article:spiderItem:export')")
    @Log(title = "采集来源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GptSpiderItem gptSpiderItem)
    {
        List<GptSpiderItem> list = gptSpiderItemService.selectGptSpiderItemList(gptSpiderItem);
        ExcelUtil<GptSpiderItem> util = new ExcelUtil<GptSpiderItem>(GptSpiderItem.class);
        util.exportExcel(response, list, "采集来源数据");
    }

    /**
     * 获取采集来源详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:spiderItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gptSpiderItemService.selectGptSpiderItemById(id));
    }

    /**
     * 新增采集来源
     */
    @PreAuthorize("@ss.hasPermi('article:spiderItem:add')")
    @Log(title = "采集来源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GptSpiderItem gptSpiderItem)
    {
        return toAjax(gptSpiderItemService.insertGptSpiderItem(gptSpiderItem));
    }

    /**
     * 修改采集来源
     */
    @PreAuthorize("@ss.hasPermi('article:spiderItem:edit')")
    @Log(title = "采集来源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GptSpiderItem gptSpiderItem)
    {
        return toAjax(gptSpiderItemService.updateGptSpiderItem(gptSpiderItem));
    }

    /**
     * 删除采集来源
     */
    @PreAuthorize("@ss.hasPermi('article:spiderItem:remove')")
    @Log(title = "采集来源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gptSpiderItemService.deleteGptSpiderItemByIds(ids));
    }


    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('article:spiderItem:edit')")
    @Log(title = "来源管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody GptSpiderItem spiderItem)
    {
        return toAjax(gptSpiderItemService.updateItemStatus(spiderItem));
    }
}
